package com.hualan.mapper;

import com.hualan.pojo.Problem;
import com.hualan.pojo.Problems;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProblemMapper {
    @Select(value = "select n.*, count(h.id) count from (select p.*, u.nickname nickname from problems p join users u on u.id = p.uid) n LEFT JOIN huifudayi h on n.id = h.pid GROUP BY n.id")
    List<Problems> listAll();
    @Select(value = "select p.*, u.nickname nickname from problems p join users u on u.id = p.uid where p.id = #{id}")
    Problems listByPid(@Param("id") Integer pid);
    @Select(value = "select id from problems where uid = #{uid}")
    List<Integer> listIdByUid(@Param("uid") Integer uid);
    @Insert(value = "insert into problems (content, title, time, uid) value(#{p.content},#{p.title},#{p.time},#{p.uid})")
    Integer add(@Param("p") Problems problem);
}
